/* Reverse polish notation calculator. */

%{
#include "identifierTable.h"
extern identifierTable *idTable;
%}

%token SELECT FROM ID ON NON EMPTY

%% /* Grammar rules and actions follow */

/*

select_statement: SELECT axis_specification FROM cube_specification
{ printf("select over axis %s on cube %s", getIdentifier(idTable, $2), getIdentifier(idTable,$4)); }
;

*/

/**
 * Select statement
 */

  select_statement:
    SELECT axis_specification_list
    FROM cube_specification;

/**
 * Axis specification
 */

  axis_specification_list:
    axis_specification
    |
    axis_specification ',' axis_specification_list;

  axis_specification:
        non_empty_opt expression dim_props_opt ON axis_name;

  non_empty_opt: | NON EMPTY;

  dim_props_opt: | dim_props;

  dim_props: ;

  axis_name: identifier;

  expression: expression ':' value_expression | value_expression;

  value_expression: term;

  term: factor;

  factor: value_expression_primary;

  value_expression_primary:
    identifier;

/**
 * Cube specification
 */

  cube_specification: cube_name;

  cube_name: compound_id;

/**
 * Generic non-terminals
 */

compound_id: identifier;

identifier: ID;

%%

